<!DOCTYPE HTML>
<html lang="cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
  <%include("/common/header.html",{title:''}){}%>
  <title>企业商家认证管理</title>
</head>
<body>


<div class="x-nav" style="margin-top: 30px;margin-left: 30px">
      <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
        <a href="javascript:;">首页</a><span lay-separator="">/</span>
        <a href="javascript:;">会员管理</a><span lay-separator="">/</span>
          <a href="javascript:;">商家认证管理</a><span lay-separator="">/</span>
        <a><cite>企业商家认证管理</cite></a>
      </span>
  <a class="layui-btn layui-btn-primary layui-btn-small" style="margin-top:4px;float:right;"
     href="javascript:location.replace(location.href)" ; title="刷新">
    <i class="layui-icon layui-icon-refresh-3"></i>
  </a>
</div>
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
      <script type="text/html" id="toolbarDemo">
        <button class="layui-btn layuiadmin-btn-useradmin">企业商家信息</button>
      </script>
      <script type="text/html" id="table-useradmin-webuser">
        {{#  if(d.code==2){ }}
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <a id="agree" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="agree"><i
                class="layui-icon layui-icon-edit"></i>同意申请</a>
        <a id="refuse" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="refuse"><i
                class="layui-icon layui-icon-edit"></i>拒绝申请</a>
        {{#  }else if( d.code==5){ }}
        <a style="margin-left: 25px;" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="view"><i
                class="layui-icon layui-icon-edit"></i>查看</a>
        <a id="agreed" class="layui-btn layui-btn-normal layui-btn-xs" style="background-color: gray;margin-left: 50px;"
           lay-event=""><i class="layui-icon layui-icon-edit"></i>已同意</a>
        {{#  }else if( d.code==1){ }}
        <a style="margin-left: 12px;" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="reason1"><i
                class="layui-icon layui-icon-edit"></i>拒绝原因</a>
        <a id="refused" class="layui-btn layui-btn-normal layui-btn-xs"
           style="background-color: gray;margin-left: 10px;" lay-event=""><i class="layui-icon layui-icon-edit"></i>已拒绝</a>
        {{#  } }}
      </script>
    </div>
  </div>
</div>

<!-- 弹出查看页面 -->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin"
     id="layuiadmin-form-useradmin1"
     style="padding: 15px;display: none">
  <form action class="layui-form" lay-filter="component-form-element1" id="myform1">
    <div class="layui-form-item">
      <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">机构名称:</label>
      <div class="layui-input-inline">
        <input type="text" id="name1" name="name" disabled class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">固定电话:</label>
      <div class="layui-input-inline">
        <input disabled style="float:left;width: 140px;" type="text" id="tel1" name="tel" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">企业联系人:</label>
      <div class="layui-input-inline">
        <input disabled style="float:left;width: 140px;" type="text" id="contacts1" name="contacts" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">机构类型:</label>
      <div class="layui-input-inline" style="width: 555px">
        <input disabled style="float:left;width: 140px;" type="text" id="type11" name="type1" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">机构地址:</label>
      <div class="layui-input-inline">
        <input disabled style="float:left;width: 140px;" type="text" id="address1" name="address" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">机构资质： &nbsp;</label>
        <div class="layui-input-inline" style="width: 150px;">
          <div class="layui-upload-list">
            <img class="layui-upload-img" width="100px" height="80px" id="demo2"/>
            <p id="demoText1"></p>
          </div>
        </div>
      </div>
    </div>

  </form>
</div>

<!-- 弹出修改页面 -->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin"
     id="layuiadmin-form-useradmin"
     style="padding: 15px;display: none">
  <form action class="layui-form" lay-filter="component-form-element" id="myform">
    <input type="hidden" name="Nature" id="Nature" value="0"/>
    <input type="hidden" name="id">
    <input type="hidden" name="account">
    <div class="layui-form-item">
      <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">机构名称:</label>
      <div class="layui-input-inline">
        <input type="text" name="name" lay-verify="required" value="" class="layui-input"
               placeholder="请输入机构名称">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">固定电话:</label>
      <div class="layui-input-inline">
        <input type="text" name="tel" lay-verify="required" value="" class="layui-input"
               placeholder="请输入固定电话">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">企业联系人:</label>
      <div class="layui-input-inline">
        <input type="text" name="contacts" lay-verify="required" value="" class="layui-input"
               placeholder="请输入企业联系人">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">机构类型:</label>
      <div class="layui-input-inline">
        <select style="height: 40px;width: 70px" lay-verify="required" id="type1" name="type1">
        </select>
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">企业地址:</label>
      <div class="layui-input-inline">
        <input type="text" name="address" lay-verify="required" value="" class="layui-input"
               placeholder="请输入企业地址">
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label" style="padding-left: 0px;font-size: medium;width: auto;">机构资质： &nbsp;</label>
        <div class="layui-input-inline" style="width: 150px;">
          <button type="button" class="layui-btn" id="upload1">上传图片</button>
          <div class="layui-upload-list">
            <img class="layui-upload-img" width="100px" height="80px" id="demo1"/>
            <p id="demoText"></p>
          </div>
        </div>
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-input-block" style="margin-left: 240px;">
        <button class="layui-btn" lay-submit="" lay-filter="component-form-element">立即提交</button>
      </div>
    </div>
  </form>
</div>
<script id="demo" type="text/html">
  <option value="">请选择</option>
  {{#  layui.each(d.list, function(index, item){ }}

  <option {{d.type1 == item.type1?"selected":""}} value="{{ item.type1 }}">{{item.type1}}</option>

  {{#  }); }}
  {{#  if(d.list.length === 0){ }}
  <option disabled value="">无</option>
  {{#  } }}
</script>

</div>
<%include("/common/foot.html"){}%>
<script>
  layui.config({
    base: 'static/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table', 'form', 'layedit', 'laydate'], function () {
    var $ = layui.$;
    var table = layui.table;
    var form = layui.form;
    var title = "";
    var size = ['600px', '500px'];
    var findAll_url = 'system/enterprise/findAll.json';
    var agree_url = 'system/enterprise/agree.json';
    var refuse_url = 'system/enterprise/refuse.json';
    var update_url = 'system/enterprise/update.json';
    var index;//定义建立富文本编辑器全局变量
    var layedit//定义富文本编辑器layedit全局变量
    var cols = [ //表头
      {field: 'name', title: '机构名称', fixed: 'left'},
      {field: 'tel', title: '固定电话'},
      {field: 'contacts', title: '企业联系人'},
      {field: 'type1', title: '机构类型'},
      {field: 'address', title: '企业地址'},
      {
        field: 'enterpriceInfoImgs',
        title: '机构资质',
        //templet: "<div><img src={{(d.enterpriceInfoImgs||{}).image||''}} style='width:30px;height:30px'></div>"
        templet: function (d) {
          return "<div class=\"layer-photos\"><img layer-src=" + (d.enterpriceInfoImgs || {}).image + " src=" + (d.enterpriceInfoImgs || {}).image + " style='width:30px;height:30px' alt=" + d.name + "></div>"
        }
      },
      {title: '操作', width: 270, toolbar: '#table-useradmin-webuser', fixed: 'right'}
    ]

    table.render({
      elem: '#LAY-user-manage',
      id: 'listReload',
      toolbar: '#toolbarDemo',
      title: title,
      url: findAll_url,
      page: true, //开启分页
      limits: [10, 20, 30, 50], //控制多少行一页（默认五条一页）
      defaultToolbar: ['filter', 'print', 'exports'],
      cols: [cols],
      done:function() {
        //alert() 数据渲染完的方法
        layer.photos({
          photos: '.layer-photos'
          , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
        });
      }
    });

    //初始化修改页面

    function loadData(data) {
      var ret = {
        "id": data.id,
        "name": data.name,
        "tel": data.tel,
        "contacts": data.contacts,
        "type1": data.type1,
        "address": data.address,
      }
      if (data.enterpriceInfoImgs != null) {
        $("#demo1").attr("src", data.enterpriceInfoImgs.image);
      }
      // $("#classifys").val(data.classifys.id);
      // $("#introduce").val(data.introduce);
      form.render();
      return ret;
    }

    //图片上传
    layui.use('upload', function () {
      var $ = layui.jquery, upload = layui.upload;
      var uploadInst = upload.render({
        elem: '#upload1',
        auto: false,
        multiple: true,
        number: 6,
        choose: function (obj) {
          obj.preview(function (index, file, result) {//预读本地文件示例，不支持ie8
            console.log(JSON.stringify(obj));
            console.log(JSON.stringify(file));
            $('#demo1').attr('src', result); //图片链接（base64）
          });
        }
      });
    });

    //编辑
    function initUpdate(data) {
      var a = layer.open({
        type: 1,
        title: title,
        content: $('#layuiadmin-form-useradmin'),
        btn: ['关闭'], //可以无限个按钮
        cancel: function (index, layero) {//取消事件
          location.replace(location.href);　//layer.open关闭刷新
        },
        success: function (layero, index) {
          layer.iframeAuto(index);
        }
      });
      layer.full(a);
      //机构类型
      $.ajax({
        url: "system/enterpriceType/getOne.json",
        type: "POST",
        data: {},
        dataType: "json",
        success: function (ret) {
          var laytpl = layui.laytpl;
          var rets = { //数据
            "list": ret,
            "type1":data.type1
          };
          laytpl($("#demo").html()).render(rets, function (html) {
            $("#type1").html(html);
          });
          // $("#classifys").val(ret.name);
          form.render();

        },
        error: function (jqXHR, textStatus, errorThrown) {

        }
      });
      /*//富文本编辑器
      layedit = layui.layedit;
      //建立编辑器
      index = layedit.build('introduce', {
          tool: ['strong', 'italic', 'underline', 'del', '|',
              'left', 'center', 'right', '|',
              'link', 'unlink',],
          height: 280
      });*/

      //富文本表单验证
      /* form.verify({
           introduce: function (value) {
               var val = layedit.getText(index);
               //alert(val.length)
               if (val.length < 6) {

                   return '内容至少6个字符'
               }
           }
       });*/
      //如果是添加则重置表单，如果是编辑则给表单赋值
      if (data == 0 || data == null) {
        $('#myform')[0].reset();
        return;
      } else {
        layui.form.val("component-form-element", loadData(data));
      }
    }

    //弹出查看页面调用初始化数据方法
    function initUpdate1(data) {
      var a = layer.open({
        type: 1,
        title: title,
        content: $('#layuiadmin-form-useradmin1'),
        btn: ['关闭'], //可以无限个按钮
        cancel: function (index, layero) {//取消事件
          //location.replace(location.href);　//layer.open关闭刷新
        },
        success: function (layero, index) {
          layer.iframeAuto(index);
        }
      });
      layer.full(a);
      //给表单赋值
      $("#tel1").val(data.tel);
      $("#name1").val(data.name);
      $("#contacts1").val(data.contacts);
      $("#type11").val(data.type1);
      $("#address1").val(data.address);
      $("#demo2").attr("src", data.enterpriceInfoImgs.image);
      //layui.form.val("component-form-element1", loadData(data));

    }

    //修改页面的内容提交到后台处理
    form.on('submit(component-form-element)', function (data) {
      // data.field.workexperience = layedit.getContent(index);
      postUpdate(data);
      return false;
    });

    //点击每行右工具栏“操作”里面按钮效果
    table.on('tool(LAY-user-manage)', function (obj) {
      var data = obj.data;
      if (obj.event === 'agree') {
        $.ajax({
          url: agree_url,
          type: "POST",
          data: {
            "id": data.id,
          },
          dataType: "json",
          success: function (ret) {
            //alert(ret.code)
            layer.msg(ret.msg, {icon: 6});

            setTimeout(function () {

              window.location.reload();
            }, 1000);

          },
          error: function (jqXHR, textStatus, errorThrown) {
            var estr = "Page:" + window.location.pathname + ",Function: postDelete()";
            layer.open({
              title: "错误信息",
              area: ['600px', '600px'],
              type: 2,
              content: "base/error.jhtml?info=" + estr, //
              btn: ['关闭'] //可以无限个按钮
            });
          }
        });
      } else if (obj.event === 'edit') {
        initUpdate(data);
      } else if (obj.event === 'view') {
        initUpdate1(data);
      } else if (obj.event === 'refuse') {
        layer.prompt({title: '请输入驳回原因', formType: 2}, function (text, index) {
          layer.close(index);
          $.ajax({
            url: refuse_url,
            type: "POST",
            data: {
              "id": data.id,
              "code": 1,
              "reason1": text
            },
            dataType: "json",
            success: function (ret) {
              layer.msg(ret.msg, {icon: 6});
              setTimeout(function () {
                window.location.reload();
              }, 1000);
            },
            error: function (jqXHR, textStatus, errorThrown) {
              var estr = "Page:" + window.location.pathname + ",Function: postDelete()";
              layer.open({
                title: "错误信息",
                area: ['600px', '600px'],
                type: 2,
                content: "base/error.jhtml?info=" + estr, //
                btn: ['关闭'] //可以无限个按钮
              });
            }
          });
        });
      } else if (obj.event === 'reason1') {
        layer.alert(data.reason1)
      }
    });

    //ajax提交修改内容
    window.postUpdate = function (data) {
      var formData = new FormData();
      formData.append("data", JSON.stringify(data.field));
      formData.append("file", $("input[name='file']")[0].files[0]);
      formData.append("file1", $("input[name='file']")[0].files[1]);
      formData.append("file2", $("input[name='file']")[0].files[2]);
      formData.append("file3", $("input[name='file']")[0].files[3]);
      formData.append("file4", $("input[name='file']")[0].files[4]);
      formData.append("file5", $("input[name='file']")[0].files[5]);
      $.ajax({
        url: update_url,
        type: "POST",
        //traditional:true,
        data: formData,
        processData: false,
        contentType: false,
        success: function (data) {
          if (data.code == 1) {
            layer.closeAll();
            layer.msg(data.msg, {time: 600, icon: 1}, function () {
              //table.reload('listReload');
              location.replace(location.href);
            });
          } else {
            layer.msg(data.msg, {icon: 5});
          }
        },
        error: function (jqXHR, textStatus, errorThrown) {
          var estr = "Page:" + window.location.pathname + ",Function:postUpdate()";
          layer.open({
            title: "错误信息",
            type: 2,
            content: "base/error.jhtml?info=" + estr,
            btn: ['关闭'] //可以无限个按钮
          });
        }
      });
    }

  });

</script>
</body>

</html>
